package com.itheima.common.threadlocal;

import com.itheima.common.vo.UserInfo;

public class UserHolder {

    private static ThreadLocal<UserInfo> TL = new ThreadLocal<>();

    public  static void setUserInfo(UserInfo userInfo){
        TL.set(userInfo);
    }

    public static UserInfo getUserInfo(){
        return TL.get();
    }

    /**
     * 获取当前认证用户-企业ID
     * @return
     */
    public static Long getCompanyId(){
        return TL.get().getCompanyId();
    }

    /**
     * 获取当前认证用户-员工ID
     * @return
     */
    public static Long getCompanyUserId(){
        return TL.get().getId();
    }

    public static void remove(){
        TL.remove();
    }
}
